import React, { useReducer } from 'react';

const myReducer = (state, action) => {
  switch (action.type) {
    case 'setCount':
      return {
        ...state,
        count: state.count + 1
      }
    default:
      return state;
  }
}

const App = () => {
  // useReducer action 钩子
  // useReducer 和 useState 有什么区别
  // useReducer 是一个加强版的useState
  const [state, dispatch] = useReducer(myReducer, { count: 0 });
  return (
    <div>
      {state.count}
      <button onClick={() => {
        dispatch({ type: "setCount" })
      }}>Click+++</button>
    </div>
  );
}

export default App;
